home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / Qpopper / pop_get_command.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-01  |  3.8 KB  |  106 lines

  1. /*
  2.  * Copyright (c) 1989 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  */
  6.  
  7. #ifndef lint
  8. static char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  9. static char SccsId[] = "@(#)@(#)pop_get_command.c    2.1  2.1 3/18/91";
  10. #endif
  11.  
  12. #include <stdio.h>
  13. #include <sys/types.h>
  14. #if defined(SOLARIS2) || defined(SYSV) || defined(AIX)
  15. #include <string.h>
  16. #else
  17. #include <strings.h>
  18. #endif
  19. #include "popper.h"
  20.  
  21. /* 
  22.  *  get_command:    Extract the command from an input line form a POP client
  23.  */
  24.  
  25. static state_table states[] = {
  26.         auth1,  "user", 1,  1,  pop_user,   {auth1, auth2},
  27.         auth2,  "pass", 1,  1,  pop_pass,   {halt,  trans},
  28. #ifdef RPOP
  29.         auth2,  "rpop", 1,  1,  pop_rpop,   {halt,  trans},
  30. #endif
  31. #ifdef APOP
  32.         auth1,  "apop", 2,  2,  pop_apop,   {halt,  trans},
  33. #endif
  34.         auth1,  "quit", 0,  0,  pop_quit,   {halt,  halt},
  35.         auth2,  "quit", 0,  0,  pop_quit,   {halt,  halt},
  36.         trans,  "stat", 0,  0,  pop_stat,   {trans, trans},
  37.         trans,  "list", 0,  1,  pop_list,   {trans, trans},
  38.         trans,  "retr", 1,  1,  pop_send,   {trans, trans},
  39.         trans,  "dele", 1,  1,  pop_dele,   {trans, trans},
  40.         trans,  "noop", 0,  0,  NULL,       {trans, trans},
  41.         trans,  "rset", 0,  0,  pop_rset,   {trans, trans},
  42.         trans,  "top",  2,  2,  pop_send,   {trans, trans},
  43.         trans,  "last", 0,  0,  pop_last,   {trans, trans},
  44.         trans,  "xtnd", 1,  99, pop_xtnd,   {trans, trans},
  45.         trans,  "uidl", 0,  1,  pop_uidl,   {trans, trans},
  46.         trans,  "euidl",0,  1,  pop_euidl,  {trans, trans},
  47.         trans,  "quit", 0,  0,  pop_updt,   {halt,  halt},
  48.         (state) 0,  NULL,   0,  0,  NULL,       {halt,  halt},
  49. };
  50.  
  51. state_table *pop_get_command(p,mp)
  52. POP             *   p;
  53. register char   *   mp;         /*  Pointer to unparsed line 
  54.                                     received from the client */
  55. {
  56.     state_table     *   s;
  57.     char                buf[MAXMSGLINELEN];
  58.  
  59.     /*  Save a copy of the original client line */
  60. #ifdef DEBUG
  61.     if(p->debug) strncpy(buf, mp, sizeof(buf));
  62. #endif
  63.  
  64.     /*  Parse the message into the parameter array */
  65.     if ((p->parm_count = pop_parse(p,mp)) < 0) return(NULL);
  66.  
  67.     /*  Do not log cleartext passwords */
  68. #ifdef DEBUG
  69.     if(p->debug){
  70.         if(strcmp(p->pop_command,"pass") == 0)
  71.             pop_log(p,POP_DEBUG,"Received: \"%s xxxxxxxxx\"",p->pop_command);
  72.         else {
  73.             /*  Remove trailing <LF> */
  74.             buf[strlen(buf)-2] = '\0';
  75.             pop_log(p,POP_DEBUG,"Received: \"%s\"",buf);
  76.         }
  77.     }
  78. #endif
  79.  
  80.     /*  Search for the POP command in the command/state table */
  81.     for (s = states; s->command; s++) {
  82.  
  83.         /*  Is this a valid command for the current operating state? */
  84.         if (strcmp(s->command,p->pop_command) == 0
  85.              && s->ValidCurrentState == p->CurrentState) {
  86.  
  87.             /*  Were too few parameters passed to the command? */
  88.             if (p->parm_count < s->min_parms)
  89.                 return((state_table *)pop_msg(p,POP_FAILURE,
  90.                     "Too few arguments for the %s command.",p->pop_command));
  91.  
  92.             /*  Were too many parameters passed to the command? */
  93.             if (p->parm_count > s->max_parms)
  94.                 return((state_table *)pop_msg(p,POP_FAILURE,
  95.                     "Too many arguments for the %s command.",p->pop_command));
  96.  
  97.             /*  Return a pointer to the entry for this command in 
  98.                 the command/state table */
  99.             return (s);
  100.         }
  101.     }
  102.     /*  The client command was not located in the command/state table */
  103.     return((state_table *)pop_msg(p,POP_FAILURE,
  104.         "Unknown command: \"%s\".",p->pop_command));
  105. }
  106.